import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex);
const config = {
    plugins: [createPersistedState()],
    state: {
        baseUrl: process.env.VUE_APP_BASE_API,
        isLogin: false,
        userName: '',
        chnName: '',
        token: '',
        tokenFG: '',
        sessionId: '',
        area: '',
        isTrue: false,
        title: process.env.VUE_APP_TITLE,
        companySysType: "",
        hasArrow: true,
        CompanyCode: '',
        openId: '',
        roles: [],
        ClassifysData: {},
        classifysChildren: [],
        resultID: "",
        trainingPlanData: "",
        setPlanExamData: "",
        envCode: "",
        catalogNum: 0,
        isTempUser: false,
        hasEquCatalog: false,
        hasRiskControl: false,
        hasLesseeCatalog: false,
        isFW: false,
        isJGB: false,
        navTo: '',
        Industry:'',
        IndustryName: "",
        CompanyType:'',
        DeptCode:'',
        isFkManager:false
    },
    getters: {
        isLogin: state => state.isLogin,
        token: state => state.token,
        tokenFG: state => state.tokenFG,
        userName: state => state.userName,
        chnName: state => state.chnName,
        area: state => state.area,
        isTrue: state => state.isTrue,
        title: state => state.title,
        hasArrow: state => state.hasArrow,
        baseUrl: state => state.baseUrl,
        CompanyCode: state => state.CompanyCode,
        openId: state => state.openId,
        roles: state => state.roles,
        ClassifysData: state => state.ClassifysData,
        classifysChildren: state => state.classifysChildren,
        resultID: state => state.resultID,
        trainingPlanData: state => state.trainingPlanData,
        setPlanExamData: state => state.setPlanExamData,
        companySysType: state => state.companySysType,
        envCode: state => state.envCode,
        catalogNum: state => state.catalogNum,
        hasEquCatalog: state => state.hasEquCatalog,
        hasRiskControl: state => state.hasRiskControl,
        hasLesseeCatalog: state => state.hasLesseeCatalog,
        isFW: state => state.isFW,
        isJGB: state => state.isJGB,
        navTo: state => state.navTo,
        Industry: state => state.Industry,
        IndustryName: state => state.IndustryName,
        CompanyType: state => state.CompanyType,
        DeptCode: state => state.DeptCode,
        isFkManager: state=>state.isFkManager
    },
    mutations: {
        updatePath(state, payload) {
            state.isTrue = payload;
        },
        updateLogin(state, payload) {
            state.isLogin = payload;
        },
        updateToken(state, payload) {
            state.token = payload;
        },
        updateTokenFG(state, payload) {
            state.tokenFG = payload;
        },
        updateUserName(state, payload) {
            state.userName = payload;
        },
        updateChnName(state, payload) {
            state.chnName = payload;
        },
        updateArea(state, payload) {
            state.area = payload;
        },
        updateTitle(state, payload) {
            state.title = payload;
        },
        updateHasArrow(state, payload) {
            state.hasArrow = payload;
        },
        updateCompanyCode(state, payload) {
            state.CompanyCode = payload;
        },
        updateCompanySysType(state, payload) {
            state.companySysType = payload;
        },
        updateOpenId(state, payload) {
            state.openId = payload;
        },
        setRoles(state, roles) {
            state.roles = roles.join(',');
        },
        setClassifysData(state, ClassifysData) {
            state.ClassifysData = ClassifysData;
        },
        setClassifysChildren(state, payload) {
            state.classifysChildren = payload;
        },
        setBaseUrl(state, payload) {
            state.baseUrl = payload;
        },
        updateResultID(state, payload) {
            state.resultID = payload;
        },
        updataTrainingPlanData(state, payload) {
            state.trainingPlanData = payload;
        },
        updataSetPlanExamData(state, payload) {
            state.setPlanExamData = payload;
        },
        setEnvCode(state, payload) {
            state.envCode = payload;
        },
        setCatalogNum(state, payload) {
            state.catalogNum = payload;
        },
        setIsTempUser(state, payload) {
            state.isTempUser = payload;
        },
        setHasEquCatalog(state, payload) {
            state.hasEquCatalog = payload;
        },
        setHasRiskControl(state, payload) {
            state.hasRiskControl = payload;
        },
        setHasLesseeCatalog(state, payload) {
            state.hasLesseeCatalog = payload;
        },
        setIsFW(state, payload) {
            state.isFW = payload;
        },
        setIsJGB(state, payload) {
            state.isJGB = payload;
        },
        setNavTo(state, payload) {
            state.navTo = payload;
        },
        setIndustry(state, payload) {
            state.Industry = payload;
        },
        setIndustryName(state, payload) {
            state.IndustryName = payload;
        },
        setCompanyType(state, payload) {
            state.CompanyType = payload;
        },
        setDeptCode(state, payload) {
            state.DeptCode = payload;
        },
        setIsFkManager(state,payload){
            state.isFkManager=payload
        }

    },
    actions: {
        // 获取权限
        getRoles({ commit }, data) {
            return new Promise(resolve => {
                let UserKind = data
                let roleList = []
                if ((UserKind & 1) > 0 || (UserKind & 2) > 0 || (UserKind & 4) > 0 || (UserKind & 256) > 0 || (UserKind & 32768) > 0) {
                    roleList.push('admin')
                }
                if ((UserKind & 4) > 0 || (UserKind & 256) > 0 || (UserKind & 32768) > 0) {
                    roleList.push('company')
                }
                if ((UserKind & 32) > 0 || (UserKind & 4) > 0 || (UserKind & 256) > 0 || (UserKind & 32768) > 0) {
                    roleList.push('equipment')
                }
                if ((UserKind & 16) > 0 || (UserKind & 4) > 0 || (UserKind & 256) > 0 || (UserKind & 32768) > 0) {
                    roleList.push('cert')
                }
                if ((UserKind & 128) > 0 || (UserKind & 4) > 0 || (UserKind & 256) > 0 || (UserKind & 32768) > 0) {
                    roleList.push('danger')
                }
                if ((UserKind & 64) > 0 || (UserKind & 4) > 0 || (UserKind & 256) > 0 || (UserKind & 32768) > 0) {
                    roleList.push('train')
                }
                if ((UserKind & 2) > 0 || (UserKind & 4) > 0) {
                    roleList.push('depart')
                }
                commit('setRoles', roleList)
                resolve()
            })
        }
    }
}
const store = new Vuex.Store(config);
export default store;